from qfluentwidgets import ProgressRing, FluentWindow
from PySide6.QtWidgets import QWidget

class ProcessingRing(QWidget):
    """ 处理进度环 """

    def __init__(self, parent=None):
        # 获取主窗口实例
        main_window = None
        while parent:
            if isinstance(parent, FluentWindow):
                main_window = parent
                break
            parent = parent.parent()
        
        super().__init__(main_window if main_window else parent)
        self.setFixedSize(160, 160)
        
        # 创建进度环
        self.progressRing = ProgressRing(self)
        self.progressRing.setFixedSize(160, 160)
        self.progressRing.setTextVisible(True)
        
    def setValue(self, value):
        """ 设置进度值 """
        self.progressRing.setValue(value)
        
    def showEvent(self, event):
        """显示时移动到父窗口中心"""
        if self.parent():
            parent_rect = self.parent().rect()
            self.move(
                parent_rect.center().x() - self.width() // 2,
                parent_rect.center().y() - self.height() // 2
            )
        super().showEvent(event) 